<template>
  <view class="viewport">
    <view class="search-box">
      <uni-nav-bar
        dark
        :fixed="true"
        background-color="#06be9c"
        status-bar
        left-icon="left"
        title="搜索"
        :confirm-type="isHome ? 'search' : undefined"
        @clickLeft="back"
      />
      <CustomNavbar :keyWord="keyWord" />
    </view>
    <view class="search-content">
      <view class="search-history">
        <view class="search-history-title">搜索历史</view>
        <view class="search-history-list">
          <view
            class="search-history-item"
            v-for="item in historyList"
            :key="item"
            @click="handleSearchHistory(item)"
          >
            <text class="search-history-item-text">{{ item }}</text>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script setup lang="ts">
import CustomNavbar from "@/pages/Home/components/CustomNavbar.vue";
import { computed, ref } from "vue";
const back = () => {
  uni.navigateBack({
    delta: 1,
  });
};
const page = getCurrentPages();
const isHome = computed(() => {
  return page[page.length - 1].route === "pages/Home/Home";
});
const historyList = ref<string[]>(["1111", "2222", "3333", "4444", "5555"]);
const keyWord = ref<string>("");
const handleSearchHistory = (value: string) => {
  keyWord.value = value;
};
</script>

<style lang="scss" scoped>
.viewport {
  height: 100%;
  display: flex;
  flex-direction: column;
  .uni-navbar {
    border-bottom: none;
    border-color: transparent;
    ::v-deep .uni-navbar--border {
      border-bottom: none;
      border-color: transparent;
    }
    ::v-deep .uni-nav-bar-text {
      font-size: 16px;
    }
  }
  .search-content {
    flex: 1;
    background-color: #f5f5f5;
    padding: 30rpx;
    .search-history {
      display: flex;
      flex-direction: column;
      gap: 30rpx;
      .search-history-title {
        font-size: 28rpx;
        font-weight: 600;
      }
      .search-history-list {
        display: flex;
        flex-wrap: wrap;
        gap: 30rpx;
        .search-history-item {
          padding: 15rpx 30rpx;
          background-color: #fff;
          border-radius: 30rpx;
        }
      }
    }
  }
}
</style>
